/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "RULE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Rule.findAll", query = "SELECT r FROM Rule r"),
    @NamedQuery(name = "Rule.findByIdRule", query = "SELECT r FROM Rule r WHERE r.rulePK.idRule = :idRule"),
    @NamedQuery(name = "Rule.findByIdBranchenterprise", query = "SELECT r FROM Rule r WHERE r.rulePK.idBranchenterprise = :idBranchenterprise"),
    @NamedQuery(name = "Rule.findByIdEnterprise", query = "SELECT r FROM Rule r WHERE r.rulePK.idEnterprise = :idEnterprise"),
    @NamedQuery(name = "Rule.findByName", query = "SELECT r FROM Rule r WHERE r.name = :name"),
    @NamedQuery(name = "Rule.findByS3r4Value", query = "SELECT r FROM Rule r WHERE r.s3r4Value = :s3r4Value")})
public class Rule implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RulePK rulePK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 180)
    @Column(name = "NAME")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Column(name = "S3R4_VALUE")
    private Double s3r4Value;
    @JoinColumns({
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE", insertable = false, updatable = false),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private BranchEnterprise branchEnterprise;

    public Rule() {
    }

    public Rule(RulePK rulePK) {
        this.rulePK = rulePK;
    }

    public Rule(RulePK rulePK, String name, Double s3r4Value) {
        this.rulePK = rulePK;
        this.name = name;
        this.s3r4Value = s3r4Value;
    }

    public Rule(BigInteger idRule, BigInteger idBranchenterprise, BigInteger idEnterprise) {
        this.rulePK = new RulePK(idRule, idBranchenterprise, idEnterprise);
    }

    public RulePK getRulePK() {
        return rulePK;
    }

    public void setRulePK(RulePK rulePK) {
        this.rulePK = rulePK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getS3r4Value() {
        return s3r4Value;
    }

    public void setS3r4Value(Double s3r4Value) {
        this.s3r4Value = s3r4Value;
    }

    public BranchEnterprise getBranchEnterprise() {
        return branchEnterprise;
    }

    public void setBranchEnterprise(BranchEnterprise branchEnterprise) {
        this.branchEnterprise = branchEnterprise;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (rulePK != null ? rulePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rule)) {
            return false;
        }
        Rule other = (Rule) object;
        if ((this.rulePK == null && other.rulePK != null) || (this.rulePK != null && !this.rulePK.equals(other.rulePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Rule[ rulePK=" + rulePK + " ]";
    }
    
}
